package cn.crm.service.impl;

import cn.crm.dao.SysUserDao;
import cn.crm.pojo.SysUser;
import cn.crm.service.SysUserService;
import cn.crm.utils.Result;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

@Service
public class SysUserServiceImpl extends ServiceImpl<SysUserDao, SysUser> implements SysUserService {
    @Autowired
    private SysUserDao sysUserDao;

    /**
     * 登录
     * @param sysUser
     * @return
     */
    @Override
    public Result login(SysUser sysUser) {
        Result result = new Result();
        LambdaQueryWrapper<SysUser> lqw = new LambdaQueryWrapper<>();
        lqw.eq(SysUser::getUsrName,sysUser.getUsrName())
                .eq(SysUser::getUsrPassword,sysUser.getUsrPassword());
        SysUser user = sysUserDao.selectOne(lqw);
        if (ObjectUtils.isEmpty(user)){
            result.setCode(405);
            result.setMessage("登录失败");
        }else {
            result.setCode(400);
            result.setMessage("登录成功");
            result.setData(user);
        }
        return result;
    }

    @Override
    public Page<SysUser> getSysUserPageJoinSysRole(Page page) {
        return sysUserDao.getSysUserPageJoinSysRole(page);
    }
}
